from selenium import webdriver  #用于操作浏览器
from selenium.webdriver.chrome.options import Options  #用于设置谷歌浏览器
from selenium.webdriver.chrome.service import Service  #用于管理驱动
from selenium.webdriver.common.by import By
import time
#设置浏览器、启动浏览器
def func():
    q1=Options()
    q1.add_argument('--no-sandbox')
    q1.add_experimental_option('detach',True)
    a1=webdriver.Chrome(service=Service('chromedriver.exe'),options=q1)
    return a1
a1=func()
#打开指定网址
a1.get('https://bahuyun.com/bdp/form/1335521405670260737')
time.sleep(2)
for  x in range(2):
    #操作单选框
    a1.find_element(By.XPATH,'//*[@id="my-node"]/div[1]/div/div[2]/div/div/div[1]').click()
    time.sleep(2)
    a1.find_element(By.XPATH,'//*[@id="my-node"]/div[1]/div/div[2]/div/div/div[2]').click()
    time.sleep(2)
    a1.find_element(By.XPATH,'//*[@id="my-node"]/div[1]/div/div[2]/div/div/div[3]').click()
    #操作多选框
    a1.find_element(By.XPATH,'//*[@id="my-node"]/div[2]/div/div[2]/div/div/div[1]/span').click()
    a1.find_element(By.XPATH,'//*[@id="my-node"]/div[2]/div/div[2]/div/div/div[2]/span').click()
    a1.find_element(By.XPATH,'//*[@id="my-node"]/div[2]/div/div[2]/div/div/div[3]/span').click()
    time.sleep(2)
    #操作下拉元素
    a1.find_element(By.XPATH,'//*[@id="my-node"]/div[3]/div/div[2]/div/div/div/select/option[2]').click()
    #操作评星
    a1.find_element(By.XPATH,'//*[@id="my-node"]/div[4]/div/div[2]/div/div[1]/div[2]/div[2]/i[1]').click()
    a1.find_element(By.XPATH,'//*[@id="my-node"]/div[4]/div/div[2]/div/div[2]/div[2]/div[5]/i[1]').click()
    #操作日期
    a1.find_element(By.XPATH,'//*[@id="input--W2vbG04d963X3l_Xyz_w"]').send_keys("0020031024")
    #提交表单
    a1.find_element(By.XPATH,'//*[@id="submit-button"]').click()
    time.sleep(3)
    #点击再填一次
    a1.find_element(By.XPATH,'//*[@id="app"]/div/div/div[1]/div[2]/div[3]/button').click()

    time.sleep(2)
    #获取全部标签页句柄
    a2=a1.window_handles
    print(a2)
    #通过句柄切换标签页
    a1.switch_to.window(a2[1])
    #获取当前标签页句柄
    a2=a1.current_window_handle
    print(f'当前标签页的句柄：{a2}')

